# ==============================================================================
# Main Makefile - Flutter Project Controller
# ==============================================================================

# --- 1. Include all submodule Makefiles ---
# This is the core mechanism to load all platform-specific tasks.
# The order doesn't matter much, but it's good practice to keep it consistent.
# Make will process all included files before executing any target.
include make/common.mk
include make/android.mk
include make/ios.mk
include make/web.mk
# include make/macos.mk # Assuming you also have a macos.mk file

# --- 2. Define user-facing alias targets ---
# These targets are what developers will typically use.
# They are short, memorable, and delegate the work to the more specifically
# named targets defined in the .mk files.


.PHONY: build-android build-ios build-web build-macos build-all
.PHONY: run-android run-ios run-web run-macos
.PHONY: clean-android clean-ios clean-web clean-macos clean-all
.PHONY: pod-install pod-deintegrate


# --- Build Targets ---
build-android: generate-version sync-android android-build-aab ## 🚀 Build Android App Bundle (for Google Play)
build-ios: generate-version sync-ios ios-ipa       ## 📦 Build iOS IPA (for TestFlight/App Store)
build-web: generate-version sync-web web-build           ## 🌐 Build the release Web application
build-macos: generate-version sync-macos macos-build         ## 💻 Build the release macOS application

build-all: build-android build-ios build-web build-macos ## ✨ Build for all platforms

# --- Run Targets ---
run-android: generate-version sync-android android-run         ## ▶️ Run on Android
run-ios: generate-version sync-ios ios-run             ## ▶️ Run on iOS
run-web: generate-version sync-web web-run             ## ▶️ Run on Web
run-macos: generate-version sync-macos macos-run           ## ▶️ Run on macOS

# --- Clean Targets ---
# Note: 'clean' is defined in common.mk for a full 'flutter clean'
clean-android: android-clean     ## 🧹 Clean Android build artifacts only
clean-ios: ios-clean           ## 🧹 Clean iOS build artifacts only
clean-web: web-clean           ## 🧹 Clean Web build artifacts only
clean-macos: macos-clean         ## 🧹 Clean macOS build artifacts only

clean-all: clean               ## 🧹 Clean everything (alias for the common 'clean' target)


pod-install: pod-install
pod-deintegrate: pod deintegrate
# --- 3. A comprehensive help target ---
# This target intelligently parses comments from THIS file and ALL included files
# to generate a complete and organized help menu.

.PHONY: help
help: ## 📚 Show this help message
	@echo "Flutter Project Makefile for [$(APP_NAME)] - v$(APP_VERSION)"
	@echo "--------------------------------------------------"
	@echo "Usage: make [target]"
	@echo ""
	@echo "Primary Build Targets:"
	@awk 'BEGIN {FS = ":.*?## "} /^(build-android|build-ios|build-web|build-macos|build-all):.*?## / {printf "  \033[36m%-25s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
	@echo ""
	@echo "Primary Run Targets:"
	@awk 'BEGIN {FS = ":.*?## "} /^(run-android|run-ios|run-web|run-macos):.*?## / {printf "  \033[36m%-25s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
	@echo ""
	@echo "Common & Utility Targets:"
	@awk 'BEGIN {FS = ":.*?## "} /^(get|clean|doctor|format|analyze|test|pod-install):.*?## / {printf "  \033[36m%-25s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort
	@echo ""


### 直接在手机上运行： flutter run --release